﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;

namespace WLWeb.Common
{
    public partial class Case : System.Web.UI.Page
    {
        BLL.wlBLL.BLL_WebExample example = new BLL.wlBLL.BLL_WebExample();
        private int pageSizeNum = 10;
        /// <summary>
        /// 每页显示的条数
        /// </summary>
        public int PageSizeNum
        {
            get { return pageSizeNum; }
            set { pageSizeNum = value; }
        }
        string Categeory = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            InitData();
        }
        protected void InitData()
        {
            if (Request.QueryString["ExampleCategoryId"] != null && Request.QueryString["ExampleCategoryId"].ToString() != "")
            {
                Categeory = Request.QueryString["ExampleCategoryId"].ToString();
            }
            DataTable dtexample=new DataTable();
            if (Categeory != "")
            {
                //DataTable dtexample1 = example.GetWebExampleInfo(new Hashtable() { { "CategoryID", Categeory } });
                dtexample = example.GetWebExampleInfo(new Hashtable() { { "CategoryID", Categeory } });
                //if (dtexample != null && dtexample.Rows.Count > 0)
                //{
                //    repDataShow.DataSource = dtexample;
                //    repDataShow.DataBind();
                //}
            }
            else
            {
                 dtexample = example.GetWebExampleInfo(new Hashtable() {});
                 //if (dtexample != null && dtexample.Rows.Count > 0)
                 //{
                 //    repDataShow.DataSource = dtexample;
                 //    repDataShow.DataBind();
                 //}
            }
            if(dtexample!=null && dtexample.Rows.Count>0 )
            {
                PagedDataSource objPds = new PagedDataSource();
                objPds.DataSource = dtexample.DefaultView;
                objPds.AllowPaging = true;
                objPds.PageSize = pageSizeNum;
                int CurPage = 0;
                if (Request.QueryString["page"] != null && !string.IsNullOrEmpty(Request.QueryString["page"].ToString()))
                    CurPage = Convert.ToInt32(Request.QueryString["Page"].ToString());
                else
                    CurPage = 0;

                objPds.CurrentPageIndex = CurPage;

                if (dtexample != null && dtexample.Rows.Count > 0)
                {
                    repDataShow.DataSource = objPds;
                    repDataShow.DataBind();
                    pagesize1.PageCount = dtexample.Rows.Count / pageSizeNum;
                    pagesize1.PageSizeNum = pageSizeNum;
                    pagesize1.PageIndex = CurPage;
                    pagesize1.DataCount = dtexample.Rows.Count;
                    pagesize1.PageUrl = "../Common/Case.aspx?ExampleCategoryId=" + Categeory + "&";
                    pagesize1.ControlInit();

                }
                else
                {
                    pagesize1.Visible = false;
                }
            }
            else
            {
                pagesize1.Visible = false;
            }

        }
    }
}